//
//  Step_table_Cell.m
//  Food
//
//  Created by dllo on 15/7/14.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Step_table_Cell.h"
#import "AFNetworkHandler.h"
#import "UIImageView+WebCache.h"
#import "BaseHeader.h"
@implementation Step_table_Cell

- (void)dealloc
{
    [_imgView release];
    [_view release];
    [_orderLable release];
    [_titleLable release];
    [super dealloc];
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imgView = [[UIImageView alloc] init];
        //self.imgView.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:self.imgView];
        
        self.view = [[UIView alloc] init];
        [self.contentView addSubview:self.view];
        
        self.orderLable = [[UILabel alloc] init];
        [self.orderLable.layer setCornerRadius:15];
        self.orderLable.layer.masksToBounds = YES;
        [self.orderLable setTextAlignment:NSTextAlignmentCenter];
        self.orderLable.backgroundColor = [UIColor orangeColor];
        [self.view addSubview:self.orderLable];
        
        self.titleLable = [[UILabel alloc] init];
//        self.titleLable.backgroundColor = [UIColor redColor];
        self.titleLable.font = [UIFont systemFontOfSize:14];
        self.titleLable.numberOfLines = 0;
        [self.view addSubview:self.titleLable];
    }
    return self;


}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.imgView.frame = CGRectMake(50 / 375.0 * ScreenWidth, 10, 275 / 375.0 * ScreenWidth, 150);
    self.view.frame = CGRectMake(self.imgView.frame.origin.x, 160, self.imgView.frame.size.width, [[self class] heightwithText:self.titleLable.text]);
    self.orderLable.frame = CGRectMake(0, 10, 30, 30);
    if (self.view.frame.size.height > 20) {
        self.titleLable.frame = CGRectMake(32 , 7, self.imgView.frame.size.width - 30, [[self class] heightwithText:self.titleLable.text]);
    } else {
        self.titleLable.frame = CGRectMake(32 , 16, self.imgView.frame.size.width - 30, [[self class] heightwithText:self.titleLable.text]);
    }
}


-(void)setData:(HomePage_show_model *)model index:(NSInteger)index{

    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.imagePath] placeholderImage:nil];
    NSLog(@"^^^^^^^^^%f", self.titleLable.frame.size.height);
    NSLog(@"+++++%f", [[Step_table_Cell class] heightwithText:model.describe]);
    self.titleLable.text = model.describe;
    self.orderLable.text = [NSString stringWithFormat:@"%02d", index+1];
}

+ (CGFloat) heightwithText:(NSString *) text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
    CGSize size = CGSizeMake(275 / 375.0 * ScreenWidth - 30, 10000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
